package com.campus.user.controller;


import com.campus.common.result.Result;
import com.campus.common.teacher.job.entity.Teacher;
import com.campus.common.teacher.job.vo.TeacherInfoVO;
import com.campus.common.teacher.service.ITeacherService;
import com.campus.common.user.entity.dto.*;
import com.campus.common.user.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/auth")
@Tag(name = "认证服务")
public class AuthController {

    @Autowired
    private AuthService authService;
    @Autowired
    private ITeacherService teacherService;

    @Operation(summary = "用户登录")
    @PostMapping("/userLogin")
    public Result register(@RequestBody LoginDTO loginDTO) {
        return authService.userLogin(loginDTO);
    }

    @Operation(summary = "用户注册")
    @PostMapping("/userRegister")
    public Result register1(@RequestBody RegisterDTO registerDTO) {
        return authService.userRegister(registerDTO);
    }

    @Operation(summary = "用户邮箱登录")
    @GetMapping("/emailLogin")
    public Result emailLogin(){
        return Result.fail("失败");
    }

    @Operation(summary = "修改用户信息")
    @PostMapping("/editUser")
    public Result editUserFun(@RequestBody EditUserDTO editUserDTO){
        return authService.editUser(editUserDTO);
    }

    @Operation(summary = "查看个人信息")
    @GetMapping("/lookOwnInfo")
    public Result lookOwnInfoFun(){
        return authService.lookOwn();
    }


    @Operation(summary = "获取教师列表")
    @GetMapping("/list")
    public Result<List<TeacherInfoVO>> teacherList(){
        List<TeacherInfoVO> list = teacherService.teacherList();
        return Result.success(list);
    }

    @Operation(summary = "获取所有用户信息")
    @PostMapping("/getAllUserInfo")
    public Result getAllUserInfo(@RequestBody LookUserDTO lookUserDTO){
        return authService.getAllUserInfo(lookUserDTO);
    }

    @Operation(summary = "删除用户信息")
    @DeleteMapping("/deleteUserInfo")
    public Result deleteUserInfo(@RequestParam Integer id){
        return authService.removeByUserId(id);
    }

    @Operation(summary = "插入管理员信息")
    @PostMapping("/insertAdmin")
    public Result insertAdminFun(@RequestBody InsertUserDTO insertUserDTO){
        return authService.insertAdmin(insertUserDTO);
    }

    @Operation(summary = "修改密码")
    @PostMapping("/change-password")
    public Result changePassword(@RequestBody LoginDTO loginDTO){
        return authService.changePassword(loginDTO);
    }
}
